package com.quick.intercprot;

import org.springframework.util.StringUtils;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @ClassName TestIntercprot
 * @Description TODO
 * @Author wangxin43
 * @Date 2018/7/24 下午3:33
 * @Version 1.0
 **/

public class TestInterceptor extends HandlerInterceptorAdapter{
	private static final String username="wang";
	private static final String pwd="123";
	@Override
	public boolean preHandle(HttpServletRequest request,
							 HttpServletResponse response, Object handler) throws Exception {
		System.out.println("preHandle start...");
		String usernameParam = request.getParameter("username");
		String pwdParam = request.getParameter("pwd");
		if(!StringUtils.isEmpty(usernameParam)&&!StringUtils.isEmpty(pwdParam)){
			if(username.equals(usernameParam)&&pwdParam.equals(pwd)){
				System.out.println("TRUE");
				return Boolean.TRUE;
			}else {
				System.out.println("FALSE");
				response.sendRedirect(request.getContextPath()+"/index/errorIndex");
				return Boolean.FALSE;
			}
		}else {
			return Boolean.TRUE;
		}
	}
}
